﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Utils.MathUtilitys
{
    public struct FRect
    {
        /*
         * Fields
         */
        float x;
        float y;
        float width;
        float height;

        /*
         * Properties
         */
        public float X { get { return x; } set { x = value; } }
        public float Y { get { return y; } set { y = value; } }
        public float Width { get { return width; } set { width = value; } }
        public float Height { get { return height; } set { height = value; } }
        public Vector2 Center { get { Vector2 v = new Vector2(); v.X = x; v.Y = y; return v; } }
        public Vector2 Size { get { Vector2 v = new Vector2(); v.X = width; v.Y = height; return v; } }

        public float Left { get { return x - width * 0.5f; } }
        public float Right { get { return x + width * 0.5f; } }
        public float Top { get { return y - height * 0.5f; } }
        public float Bottom { get { return y + height * 0.5f; } }

        /*
         * Methods
         */
        public FRect(float x, float y, float width, float height)
        {
            this.x = x;
            this.y = y;
            this.width = width;
            this.height = height;
        }

        public FRect(Vector2 pos, Vector2 size)
            : this(pos.X, pos.Y, size.X, size.Y)
        {
        }

        public static explicit operator Rectangle(FRect fRect)
        {
            Rectangle rectangle = new Rectangle();
            rectangle.X = (int)fRect.Left;
            rectangle.Y = (int)fRect.Top;
            rectangle.Width = (int)fRect.Width;
            rectangle.Height = (int)fRect.Height;
            return rectangle;
        }
    }
}
